package per.lee.spingboothelper.db.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import per.lee.spingboothelper.db.dao.BaseDao;
import per.lee.spingboothelper.db.export.SlowSqlExport;
import per.lee.spingboothelper.db.model.ShowSql;
import per.lee.spingboothelper.db.model.SlowSqlModel;
import per.lee.spingboothelper.db.service.SlowSqlService;

@RestController
@RequestMapping("/slowSql")
public class SlowSqlController {

	@Autowired
	private SlowSqlService slowSqlService;

	@RequestMapping("/export")
	public boolean exportSlowRpt(HttpServletRequest request, HttpServletResponse response,
			@RequestParam("date") String date, @RequestParam("env") String env) {
		BaseDao.ENV = env;

		String fileName = "slow_sql_" + env + "_"+date;
		List<SlowSqlModel> voList = slowSqlService.findSlowList(date);
		System.out.println("结果数：" + voList.size());
		Boolean print = SlowSqlExport.export(request, response, fileName, voList);
		return print;
	}

}